﻿using UnityEngine;
using System.Collections;

namespace AutoRoot
{
   public class HideOnTop : MonoBehaviour
   {
      public Transform [] behind;

      // Use this for initialization
      void Start()
      {
         float offsetY = 0f;
         foreach (Transform obj in behind)
         {
            Vector3 tabBottomLeft = Camera.main.WorldToScreenPoint(new Vector3(obj.renderer.bounds.min.x, obj.renderer.bounds.min.y, 0));
            Vector3 tabUpperRight = Camera.main.WorldToScreenPoint(new Vector3(obj.renderer.bounds.max.x, obj.renderer.bounds.max.y, 0));
            offsetY += (tabUpperRight.y - tabBottomLeft.y);
         }
         //Hide it on the top of screen
         Vector3 bottomLeft = Camera.main.WorldToScreenPoint(new Vector3(renderer.bounds.min.x, renderer.bounds.min.y, 0));
         Vector3 upperRight = Camera.main.WorldToScreenPoint(new Vector3(renderer.bounds.max.x, renderer.bounds.max.y, 0));
         Vector3 topOfScreen = new Vector3((float)Screen.width / 2, (float)Screen.height + ((upperRight.y - bottomLeft.y) / 2 - offsetY), 1);
         transform.position = Camera.main.ScreenToWorldPoint(topOfScreen);
      }
   }
}
